import React, { Component } from 'react'
import Child from './Child'
export default class Index extends Component {
  // 实例属性
  inputRef = React.createRef()
  childRef = React.createRef()
  //相当于vue2的mounted
  componentDidMount () {
    // console.log('--------', this.inputRef)
    this.inputRef.current.focus()
  }

  change = () => {
    // console.log(this.childRef.current)
    this.childRef.current.setState({
      age: 100
    })
  }
  render () {
    return (
      <div>
        <input type='text' ref={this.inputRef} />
        <hr />
        {/* button---用onClick    input---用onChange */}
        <p>
          <button onClick={this.change}>更改子组件的值</button>
        </p>

        <Child ref={this.childRef} />
      </div>
    )
  }
}
